<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<html>
<head>
<%@ include file="../common/static.jsp"%>
</head>
<body class="hold-transition skin-blue fixed sidebar-mini">
	<div class="wrapper">
		<%@ include file="../common/header.jsp"%>
		<%@ include file="../common/asidebar.jsp"%>
		<%@ include file="smsLogForm.jsp"%>
		<div class="content-wrapper">
		  <div class="content-header">
		      <h1>
		                       基础数据
		        <small>商品信息维护</small>  
		      </h1>
	    	  <ol class="breadcrumb">
		        <li><a href="#"><i class="fa fa-dashboard"></i></a></li>
		        <li><a href="#">基础数据</a></li>
		        <li class="active">商品信息维护</li>
		      </ol>
		    </div>
			<div class="content">
				<div class="row">
					<div class="col-xs-12">
						<div class="box">
							<div class="box-body">
								<table id="smsLogList" class="table table-bordered table-hover" cellspacing="0" width="100%" style="height:300px">
								</table>
								</div>
							</div>
						</div>
					</div>
			</div>
		</div>
	</div>
	<script>
	$(document).ready(function(){
		loadData();
		initToolbar();
	});
	
	var addSmsLog = function(){
        $('#smsLogForm')[0].reset();
        $('#smsLogDlg').modal('show');
    }
	
	var delSmsLog = function(id){
		swal({ 
		    title: "您确定要删除吗？", 
		    type: "warning", 
		    showCancelButton: true, 
		    closeOnConfirm: false, 
		    confirmButtonText: "确定", 
		    cancelButtonText:"取消",
		    confirmButtonColor: "#ec6c62" 
		}, function() { 
			$.post("<%=cx%>/interf/smsLog/del",{"id" : id},function(data){
				var result = eval('(' + data + ')');
	            if(result.code == '0'){
	            	swal("成功", "删除成功", "success");
	                reload();
	            }
	            else{
	            	swal("错误", "删除失败", "error");
	            }
            });
		});
    }
	
	var editSmsLog = function(id){
        $.post("<%=cx%>/interf/smsLog/info" ,{"id" : id},function(data){
            var result = eval('(' + data + ')');
            if(result.code == '0'){
                  var dataJson = result.data;
                  $("#id").val(dataJson.id);
                  $("#phone").val(dataJson.phone);
                  $("#content").val(dataJson.content);
                  $("#createDt").val(dataJson.createDt);
                  $("#type").val(dataJson.type);
                  $("#templateId").val(dataJson.templateId);
                  $("#param").val(dataJson.param);
                  $("#signName").val(dataJson.signName);
                  $("#createBy").val(dataJson.createBy);
            }
            $("#smsLogDlg").modal('show');
        });
    }
	
	
	var saveSmsLog = function(){
        var id = $('#id').val();
        var action = '';
        if(id == null){
            action = "<%=cx%>/interf/smsLog/create";
        }
        else
        {
            action = "<%=cx%>/interf/smsLog/update";
            
        }
        $("#smsLogForm").ajaxSubmit({
             url:action,
             success:function(data){
                 var result = eval('(' + data + ')');
                    if(result.code == '0'){
                       swal("成功","提交成功!","success"); 
                       reload();
                    }
                    else{
                    	swal("错误","提交失败,原因：" + result.msg,"error"); 
                    } 
             }
                
        });
     }
	
	var loadData = function(){
		$('#smsLogList').dataTable({
			searching: true,
            ordering: true,
            info: true,
            bServerSide: true,
            autoWidth: false,
            "dom": '<"toolbar">frtip',
            ajax: 
            {
                url: $("#contextpath").val() + '/interf/smsLog/list',
                dataSrc: 'data',
                type:"POST",
            },
            pagingType: "simple_numbers",
            processing:true,
            serverSide: true,
	        columns: [                    
                {"data":"id","title":" "},
                {"data":"phone","title":"手机号码"},
                {"data":"content","title":"内容"},
                {"data":"createDt","title":"创建时间"},
                {"data":"type","title":"短信类型（1-验证码,2-模板短信,3-推广短信）"},
                {"data":"templateId","title":"模板id"},
                {"data":"param","title":"输入参数"},
                {"data":"signName","title":"短信签名"},
                {"data":"createBy","title":"创建人"},
	            {"data":"","title":"操作"}
	        ],
	        columnDefs: [
	              {
	                  targets:3,
	                  render:function(a,b,c,d){
	                     var editBtn =  '<a type="button" class="btn btn-primary btn-xs btn-flat" onclick="editSmsLog(\'' + c.id + '\');">编辑</a>';
	                     var delBtn = '<a type="button" class="btn btn-danger btn-xs btn-flat" onclick="delSmsLog(\'' + c.id + '\');">删除</a>';
	                     var space = '&nbsp;&nbsp;';
	                     return editBtn + space + delBtn;
	                    
	                  }
	              },
	              {
	                  "defaultContent": "-",
	                  "targets": "_all"
	              }
	         ],
	         select: true,      
	    });
	}
	
	var initToolbar = function(){
        $("div.toolbar").html('<a type="button" class="btn btn-success btn-xs btn-flat" onclick="addSmsLog()">新增</a>');
    }
	
    var reload = function(){
        $("#smsLogList").dataTable().fnDraw(false);
    }
    
    var closeDlg = function(){
        $("#smsLogDlg").modal('hide');
    }
	</script>
</body>
</html>
